﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows;
using FinPlusCommon;
using log = Logger.Logger;

namespace FinPlusWPFControls
{
    public partial class FinPlusColOnOffButton : FinPlusControl
    {
        public event EventHandler<Function> ColOnOff;

        //construct
        public FinPlusColOnOffButton(string name)
        {
            InitializeComponent();
            Tag = Id = name;
            bStart.Content = name;
            IsValid = true;
        }

        //common control interface
        public override void CmdExecute(IFunction command)
        {
            try
            {
                CmdCapture(command);

                switch ((Cmds)Enum.Parse(typeof(Cmds), command.Name, true))
                {
                    case Cmds.ColOn:
                    case Cmds.ColOff: ColOnOffs(command); break;
                    default: throw new Exception(string.Format("event not recognised {0}", command.Name));
                }

            }
            catch (CmdExecuteException e)
            {
                IsValid = log.Log(Logger.Level.Warning, Id, Config, e.Message, e);
            }
        }

        //private
        private void ColOnOffs(IFunction func)
        {
            if (ColOnOff != null) ColOnOff.Invoke(this, (Function)func);
        }

        private enum Cmds { ColOn, ColOff }
    }
}
